using TerritoryGame.Domain.Common;
using TerritoryGame.Domain.ValueObjects;

namespace TerritoryGame.Domain.Entities;

public class Player : Entity<Guid>
{
    public string NickName { get; private set; }
    public PlayerColor Color { get; private set; }
    public GameScore CurrentScore { get; private set; }
    public bool IsOnline { get; private set; }
    public DateTime LastActiveAt { get; private set; }
    
    private Player() { }
    
    public Player(Guid id, string nickName, PlayerColor color) : base(id)
    {
        NickName = nickName ?? throw new ArgumentNullException(nameof(nickName));
        Color = color;
        CurrentScore = GameScore.Zero;
        IsOnline = true;
        LastActiveAt = DateTime.UtcNow;
    }
    
    public void UpdateScore(GameScore newScore)
    {
        CurrentScore = newScore;
    }
    
    public void UpdateArea(int areaChange)
    {
        var newArea = CurrentScore.Area + areaChange;
        CurrentScore = new GameScore(newArea);
    }
    
    public void ResetScore()
    {
        CurrentScore = GameScore.Zero;
    }
    
    public void SetOnlineStatus(bool isOnline)
    {
        IsOnline = isOnline;
        LastActiveAt = DateTime.UtcNow;
    }
    
    public void UpdateLastActive()
    {
        LastActiveAt = DateTime.UtcNow;
    }
}
